package homework;

/**
 * @Author Stringzhua
 * @Date 2024/2/29 20:17
 * description:编写类A03,实现数组的复制功能copyArr,输入旧数组,返回一个新数组,元素和旧数组一样
 */
public class homework04 {
    public static void main(String[] args) {
        int[] oldArr={10,30,50};
        A03 a03 = new A03();
        int[] newArr = a03.copyArr(oldArr);
        System.out.println("返回的newArr元素情况");
        for (int i = 0; i < newArr.length; i++) {
            System.out.print(newArr[i]+"\t");
        }
    }
}
class A03{
    public int[] copyArr(int[] oldArr){
        int[] newArr=new int[oldArr.length];
        //在堆中创建了一个长度为oldArr.length数组
        //遍历oldArr,将元素拷贝到newArr
        for (int i = 0; i < oldArr.length; i++) {
            newArr[i]=oldArr[i];
        }
        return newArr;
    }
}
